package com.simon.customer.urlconn;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.databind.ObjectMapper;

public class URLConnect {
	public  List<String> urlConnect(){
		HttpURLConnection conn;
		List<String> list=new ArrayList<>();
		try {//10.222.29.195
			URL url=new URL("http://10.222.29.195:8080/amc-a/GetMerchantListServlet");
			conn = (HttpURLConnection)url.openConnection();
			conn.setRequestMethod("GET");
			conn.setDoOutput(true);
			conn.setDoInput(true);
			conn.connect();		
			String result="";
			int resCode=conn.getResponseCode();		
			if(resCode==200){
				InputStream is=conn.getInputStream();
				BufferedReader br=new BufferedReader(new InputStreamReader(is));
				String line="";
				while((line=br.readLine())!=null){
					result+=line;
				}
//				System.out.println(result);
			}
			ObjectMapper mapper=new ObjectMapper();
			list=mapper.readValue(result, List.class);
		} catch (IOException e) {
			System.out.println("服务器未开启");
			//e.printStackTrace();
		}		
		
		return list;
	}
}
